﻿// This File is part of Innovation Foundry's "QualityHelper Project"
//
// Copyright  2009 Innovation Foundry Pty Ltd
// All rights reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA  02110-1301 USA
// or alternatively it may be downloaded from <http://www.gnu.org/licenses/>.

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

using InnovationFoundry.QualityHelper.Silverlight.Assets.Resources;
using InnovationFoundry.QualityHelper.Silverlight.BLL.Objects;

namespace InnovationFoundry.QualityHelper.Silverlight.Utilities
{
    public class IconHelper
    {

    }

    public class IconConverter : IValueConverter
    {
        public object Convert(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            DocumentObject d = value as DocumentObject;
            if (d != null && d.OriginURL != null)
            {
                int lastDot = d.OriginURL.LastIndexOf(".");
                if (lastDot > -1)
                {
                    string suffix = d.OriginURL.Substring(lastDot + 1, d.OriginURL.Length - lastDot - 1).ToLower();
                    if (ControlResources.SuffixesAudio.IndexOf(suffix) > -1)
                        return BitmapResources.BmpAudio;
                    if (ControlResources.SuffixesPDF.IndexOf(suffix) > -1)
                        return BitmapResources.BmpPDF;
                    if (ControlResources.SuffixesPicture.IndexOf(suffix) > -1)
                        return BitmapResources.BmpPicture;
                    if (ControlResources.SuffixesText.IndexOf(suffix) > -1)
                        return BitmapResources.BmpText;
                    if (ControlResources.SuffixesURL.IndexOf(suffix) > -1)
                        return BitmapResources.BmpURL;
                    if (ControlResources.SuffixesVideo.IndexOf(suffix) > -1)
                        return BitmapResources.BmpVideo;
                    if (ControlResources.SuffixesWin.IndexOf(suffix) > -1)
                        return BitmapResources.BmpWin;
                }
            }
            else if (d !=null && d.OriginURL == null)
                    return BitmapResources.BmpNone;
            return BitmapResources.BmpUnknown;
        }

        public object ConvertBack(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
